<template>
  <div class="app-container cjybqkView">
    <el-form ref="form" :model="form" :rules="rules">
      <BorderView title="采集一般情况" />
      <el-descriptions class="margin-top" :column="3" border>
        <el-descriptions-item label="月收入情况" label-class-name="labelBg">
          <el-form-item prop="ysrzk">
            <el-select
              v-model="form.ysrqk"
              placeholder="请输入月收入情况"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.ysrqk"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item label="身体状况*" label-class-name="labelBg">
          <el-form-item prop="stzk">
            <el-select
              v-model="form.stzk"
              placeholder="请选择身体状况"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.stzk"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item label="违法犯罪情况*" label-class-name="labelBg">
          <el-form-item prop="wffzqk">
            <el-select
              v-model="form.wffzqk"
              placeholder="请选择违法犯罪情况"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.wffzqk"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item label="当前状况*" label-class-name="labelBg">
          <el-form-item prop="dqzk">
            <el-select
              v-model="form.dqzk"
              placeholder="请选择当前状况"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.sjsk_current_zk"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item label="驾驶证是否吊销*" label-class-name="labelBg">
          <el-form-item prop="jszsfdx">
            <el-select
              v-model="form.jszsfdx"
              placeholder="请选择驾驶证是否吊销"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.jszsfdx"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item label="交往吸毒人数*" label-class-name="labelBg">
          <el-form-item prop="jwxdrs">
            <el-input
              v-model="form.jwxdrs"
              type="number"
              placeholder="请输入交往吸毒人数"
            />
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item
          label="车辆信息*"
          :span="3"
          label-class-name="labelBg"
        >
          <el-form-item label="" prop="clxx">
            <el-input v-model="form.clxx" placeholder="请输入车辆信息" />
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item
          label="社保情况状况*"
          label-class-name="labelBg"
          :span="3"
        >
          <el-form-item prop="shbzqkList">
            <el-checkbox-group v-model="form.shbzqkList" size="mini">
              <el-checkbox
                v-for="(item, index) in dict.type.shbzqk"
                :key="index"
                :label="item.value"
                >{{ item.label }}</el-checkbox
              >
            </el-checkbox-group>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item
          label="就业帮助情况状况*"
          label-class-name="labelBg"
          :span="3"
        >
          <el-form-item prop="jybzqkList">
            <el-checkbox-group v-model="form.jybzqkList" size="mini">
              <el-checkbox
                v-for="(item, index) in dict.type.jybzqk"
                :key="index"
                :label="item.value"
                >{{ item.label }}</el-checkbox
              >
            </el-checkbox-group>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item
          label="家庭状况"
          label-class-name="labelBg"
          :span="3"
        >
          <el-form-item prop="jtqk">
            <el-checkbox-group v-model="form.jtqkList" size="mini">
              <el-checkbox
                v-for="(item, index) in dict.type.jtqk"
                :key="index"
                :label="item.value"
                >{{ item.label }}</el-checkbox
              >
            </el-checkbox-group>
          </el-form-item>
        </el-descriptions-item>
        <el-descriptions-item
          label="家庭成员"
          :span="3"
          label-class-name="labelBg"
          content-class-name="contentBg"
          style="padding: 0"
        >
          <FamilyListEl :type-id="zdgzId" />
        </el-descriptions-item>
        <el-descriptions-item
          label="帮扶小组"
          :span="3"
          label-class-name="labelBg"
          content-class-name="contentBg"
          style="padding: 0"
        >
          <HelpGroupEl :type-id="zdgzId" />
        </el-descriptions-item>
        <el-descriptions-item
          label="帮扶计划*"
          :span="3"
          label-class-name="labelBg"
        >
          <el-form-item prop="helpPlan">
            <el-input v-model="form.helpPlan" placeholder="请输入内容" />
          </el-form-item>
        </el-descriptions-item>
      </el-descriptions>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
      style="text-align: right; margin-top: 20px"
    >
      <el-button @click="cancel">重置</el-button>
      <el-button :loading="buttonLoading" type="primary" @click="submitForm"
        >下一步</el-button
      >
    </div>
  </div>
</template>
<script>
import BorderView from "@/views/components/BorderTitleView/index.vue";
import FamilyListEl from "@/views/components/personnelEl/family";
import HelpGroupEl from "@/views/components/personnelEl/helpGroup";
import {
  addUser,
  updateUser,
  getUser,
} from "@/api/user/userInfo";

export default {
  components: {
    BorderView,
    FamilyListEl,
    HelpGroupEl,
  },
  dicts: [
    "ysrqk",
    "sys_yes_no",
    "stzk",
    "wffzqk",
    "sjsk_current_zk",
    "jszsfdx",
    "shbzqk",
    "jybzqk",
    "jtqk",
  ],
  props: {
    zdgzId: {
      type: String,
    },
  },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 表单参数
      form: {
        shbzqkList: [],
        jybzqkList: [],
        jtqkList: [],
      },
      // 表单校验

      rules: {
        ysrqk: [
          { required: true, message: "月收入状况不能为空", trigger: "blur" },
        ],
        stzk: [
          { required: true, message: "身体状况不能为空", trigger: "blur" },
        ],
        wffzqk: [
          { required: true, message: "违法犯罪情况不能为空", trigger: "blur" },
        ],
        dqzk: [
          { required: true, message: "当前状况不能为空", trigger: "blur" },
        ],
        jszsfdx: [
          {
            required: true,
            message: "驾驶证是否吊销不能为空",
            trigger: "blur",
          },
        ],
        jwxdrs: [
          { required: true, message: "交往吸毒人数不能为空", trigger: "blur" },
        ],
        clxx: [
          { required: true, message: "车辆信息不能为空", trigger: "blur" },
        ],
        shbzqkList: [
          { required: true, message: "社会保障情况不能为空", trigger: "blur" },
        ],
        jybzqkList: [
          { required: true, message: "就业帮助情况不能为空", trigger: "blur" },
        ],
        jtqkList: [
          { required: true, message: "家庭情况不能为空", trigger: "blur" },
        ],
        helpPlan: [
          { required: true, message: "帮扶计划不能为空", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    zdgzId: {
      immediate: true,
      handler(newV) {
        if (newV) {
          getUser(newV).then((res) => {
            if (res.data) {
              this.form = res.data;
            } else {
              this.reset();
            }
          });
        }
      },
    },
  },
  methods: {
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          updateUser(this.form)
            .then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.$emit("goto-next", 2);
            })
            .finally(() => {
              this.buttonLoading = false;
            })
        }
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ysrqk: undefined,
        stzk: undefined,
        wffzqk: undefined,
        dqzk: undefined,
        jszsfdx: undefined,
        jwxdrs: undefined,
        clxx: undefined,
        shbzqkList: [],
        jybzqkList: [],
        jtqkList: [],
        helpPlan: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
      };
      this.resetForm("form");
    },
  },
};
</script>
<style>
.labelBg {
  background: rgb(241, 243, 244) !important;
}
.contentBg {
  padding: 0 !important;
}
</style>
<style scoped>
.cjybqkView .el-input__wrapper {
  border: none !important;
  box-shadow: none !important;
  padding: 0px;
}
.cjybqkView /deep/ .el-input__inner {
  border: none !important;
}
.cjybqkView /deep/ .el-textarea__inner {
  border: none !important;
}
.cjybqkView /deep/ .el-form-item {
  margin-bottom: 0 !important;
}
</style>
